class Animal{
    String name;
    int age;
    public Animal(String name,int age){
        this.name=name;
        this.age=age;
    }
    public void eat(){
        System.out.println(name+"正在吃饭！");
    }
}

class Dog extends Animal{
    public Dog(String name,int age){
        super(name,age);
    }
    public void eat(){//构成重写
        System.out.println(name+"正在吃骨头！");
    }
    public void bark(){
        System.out.println(name+"汪汪叫！");
    }
}

class Cat extends Animal{
    public Cat(String name,int age){
        super(name,age);
    }
    public void eat(){//构成重写
        System.out.println(name+"正在吃鱼！");
    }
    public void mew(){
        System.out.println(name+"喵喵叫！");
    }
}
public class Test {
    public static void main(String[] args) {
        //向上转型
        Animal animal1=new Dog("小黄",1);
        Animal animal2=new Cat("小橘",2);
        //向下转型
        if(animal1 instanceof Dog){
            Dog dog=(Dog)animal1;
        }
        if(animal2 instanceof Cat){
            Cat cat=(Cat)animal2;
        }
    }
}
